package kandl.automation.steprunner.selenium.commands;


import kandl.automation.steprunner.selenium.Command;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.springframework.stereotype.Component;

@Component
class VerifyAttribute implements Command {
    @Override
    public void runCommand(WebDriver driver, String... params) throws Exception {

        WebElement element = driver.findElement(By.xpath(params[0]));
        if(element.isDisplayed()) {
            String temp = element.getAttribute(params[1]);
            if(!temp.equals(params[2])) {
                throw new VerificationFailedException("Parameters " + params[1] + " and " + params[2] + " are not matched.");
            }
        }  else {
            throw new WebElementNotFoundException("Xpath " + params[0] + " is not found");
        }
    }

    @Override
    public String getName() {
        return "verify_attribute";
    }
}